package com.me.customerdemo.config;

import com.me.customerdemo.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

// 作为配置类，必须使用@Configuration
@Configuration
public class AppWebMvcConfig implements WebMvcConfigurer {
    // 重写AddInterceptors方法,用于注册多个拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 向拦截器注册登录控制器，返回的InterceptorRegistration对象，可以进一步配置
        InterceptorRegistration registration = registry.addInterceptor(new LoginInterceptor());

        // 配置要拦截的请求
        registration.addPathPatterns("/**");

        // 配置不需要拦截的请求
        registration.excludePathPatterns("/login","/assets/**","/logout");
    }
}
